-
Notifications
You must be signed in to change notification settings - Fork 566
Add sym_sizes
with dynamic shape support
#3909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR shows that this implementation must be correct. However, there are other issues we want to resolves in the mentioned PR that may require extra time. This PR proposes the landing of the |
ceb2954
to
149d61e
Compare
@JackCaoG I remember you had some doubts about this PR? |
never mind, I'm seeing real failures now, need to investigate @JackCaoG |
seems OK from high level, I am not sure what does this pr enabled us through. is it |
return sizes_default(); | ||
} | ||
|
||
c10::SymIntArrayRef XLATensorImpl::sym_sizes_custom() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering what the "custom" in sym_sizes_custom()
implies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
custom
means that a given TensorImpl
can implement sym_sizes
in whichever way they see fit. Note, sym_sizes_custom
is a virtual method whereas sym_sizes()
isn't. sym_sizes()
checks if a given tensor impl implements CustomSizes
policy and if so calls a virtual sym_sizes. This is kinda convoluted and was done to make sure we don't pay a virtual call penalty on the fast path: cpu and cuda tensors don't need the custom_sym_sizes implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
torch_xla/csrc/tensor_impl.cpp
Outdated
sym_sizes_.push_back(sn); | ||
/*TODO(miladm): verify numel_ calculation after adding a dynamic op | ||
*/ | ||
numel_ *= dynamic_cast<SizeNode*>(dim_node.get())->getStaticValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read the definition of numel_ in the base class but it's not clear to me what it means. Do you know the meaning of this member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number of elements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
149d61e
to
06e9ecf
Compare
This PR finally opens the Pandora box, hehe. For ops like |
ASSERT_EQ(a.sym_sizes().at(0).is_symbolic(), false); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a dynamic test? You can call non_zero
but you would need to make sure https://github.com/pytorch/xla/blob/master/test/cpp/run_tests.sh#L11 is set so non_zero
won't fallback to cpu.
torch_xla/csrc/tensor_impl.h
Outdated
#include <torch/csrc/lazy/backend/backend_interface.h> | ||
#include <torch/csrc/lazy/core/config.h> | ||
#include <torch/csrc/lazy/core/ir.h> | ||
#include <torch/csrc/lazy/core/trie.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still needs these includes?
3954208
to
89062bd
Compare
89062bd
to
e4befa3
Compare
sizes_and_strides_.set_sizes(updated_sizes); | ||
auto updated_strides = torch::lazy::ComputeArrayStrides( | ||
torch::lazy::ToVector<int64_t>(shape.get().dimensions())); | ||
for (int i = 0; i < updated_strides.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we move this for loop inside SetupSymSizeProperties()
? This makes SetupSizeProperties
and SetupSymSizeProperties
implementations consistent. Is there a reason we want them called outside SetupSymSizeProperties
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I understand your point, you are suggesting to duplicate the strides logic inside SetupSymSizeProperties
as well, so it updates both sym_sizes and sym_strides the same way SetupSizeProperties
updates sizes and strides?
If this is your concern, I believe it's fine for now, since sym_strides
is still returning static strides now.
We should figure out if we need support for dynamic strides as well or whether it's okay for sym_strides to continue returning static strides.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ezyang: based on our offline conversation about sym_strides
under functionalization, it seems we assume no need for dynamic strides; correct?
sizes_and_strides_.stride_at_unchecked(i) = updated_strides[i]; | ||
} | ||
SetupSymSizeProperties(); | ||
generation_ = generation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
xla_b = torch::nonzero(xla_b); | ||
auto s0 = xla_b.sym_sizes().at(0); | ||
ASSERT_EQ(s0.is_symbolic(), true); | ||
auto sininode = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is the variable name meant to be sininode
?
Add
sym_sizes
with dynamic shape support